﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace login
{
    public partial class RegisterInfo : Form
    {
        public RegisterInfo()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            combogender.SelectedIndex = 0;
            combomarriage.SelectedIndex = 0;
            comboedu.SelectedIndex = 0;
            combopoli.SelectedIndex = 0;
            combohealth.SelectedIndex = 0;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }


        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            BasicForm basicform = new BasicForm();
            this.Hide();
            basicform.Show();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            String flag = "";
            UserInfoModel uim = new UserInfoModel();

            if (textname.Text.Trim() == "")
            {
                flag = "请填写姓名";
            }
            else
            {
                uim.Name = textname.Text.Trim();
            }
            if (combogender.Text == "男") {
                uim.Gender = false;
            }
            else if (combogender.Text == "女") {
                uim.Gender = true;
            }else {
                flag = "请填写性别";
            }
            uim.Birth = dateTimePicker1.Value;
            if (combohealth.Text == "良好"){
                uim.HealthState = 1;
            }
            else if (combohealth.Text == "体弱") {
                uim.HealthState = 2;
            }
            else if (combohealth.Text == "残疾") {
                uim.HealthState = 3;
            }
            else {
                flag = "请填写健康状况";
            }
            if (combomarriage.Text == "未婚") {
                uim.MarriageState = false;
            }
            else if (combomarriage.Text == "已婚") {
                uim.MarriageState = true;
            }
            else {
                flag = "请填写婚姻状况";
            }
            if (textbirthplace.Text.Trim() == "")
            {
                flag = "请填写籍贯";
            }
            else
            {
                uim.BirthPlace = textbirthplace.Text.Trim();
            }
            if (comboedu.Text == "小学") {
                uim.EducationLevel = 1;
            }
            else if (comboedu.Text == "初中") {
                uim.EducationLevel = 2;
            }
            else if (comboedu.Text == "高中") {
                uim.EducationLevel = 3;
            }
            else if (comboedu.Text == "本科") {
                uim.EducationLevel = 4;
            }
            else if (comboedu.Text == "硕士") {
                uim.EducationLevel = 5;
            }
            else if (comboedu.Text == "博士") {
                uim.EducationLevel = 6;
            }
            else
            {
                flag = "请填写文化程度";
            }
            if (combopoli.Text == "清白") {
                uim.PolicitalStatus = 1;
            }
            else if (combopoli.Text == "共青团员") {
                uim.PolicitalStatus = 2;
            }
            else if (combopoli.Text == "中共党员") {
                uim.PolicitalStatus = 3;
            }
            else if (combopoli.Text == "民主党派党员") {
                uim.PolicitalStatus = 4;
            }
            else
            {
                flag = "请填写政治面貌";
            }
            if (textidnum.Text.Trim() == "" || textidnum.Text.Trim().Length != 18)
            {
                flag = "请填写18位身份证号码";
            }
            else
            {
                uim.IDNumber = textidnum.Text.Trim();
            }
            if (textaddrbirth.Text.Trim() == "")
            {
                flag = "请填写户籍地址";
            }
            else
            {
                uim.AddressHometown = textaddrbirth.Text.Trim();
            }
            if (textaddrnow.Text.Trim() == "")
            {
                flag = "请填写现住地址";
            }
            else
            {
                uim.AddressNow = textaddrnow.Text.Trim();
            }
            if (textphone.Text.Trim() == "")
            {
                flag = "请填写电话";
            }
            else
            {
                uim.Telephone = textphone.Text.Trim();
            }
            if (checkadmin.Checked == true){
                uim.Privilege = 1;
            }else {
                uim.Privilege = 0;
            }

            if(flag != ""){
                MessageBox.Show(flag);
                return;
            }
            String uimstr = uim.EntityToJson(uim);

            List<SocialRelationModel> srml = new List<SocialRelationModel>();
            SocialRelationModel srm = new SocialRelationModel();
            if(sr1appe.Text.Trim() != "" && sr1age.Text.Trim() != "" && sr1name.Text.Trim() != "" && sr1cap.Text.Trim() != ""){
                try
                {
                    srm.Age = Convert.ToInt32(sr1age.Text.Trim());
                }
                catch 
                {
                    flag = "请在年龄栏中填写数字";
                }
                srm.Appellation = sr1appe.Text.Trim();
                srm.Name = sr1name.Text.Trim();
                srm.Company_And_Phone = sr1cap.Text.Trim();
                srml.Add(srm);
            }
            if (sr2appe.Text.Trim() != "" && sr2age.Text.Trim() != "" && sr2name.Text.Trim() != "" && sr2cap.Text.Trim() != "")
            {
                try
                {
                    srm.Age = Convert.ToInt32(sr2age.Text.Trim());
                }
                catch
                {
                    flag = "请在年龄栏中填写数字";
                }
                srm.Appellation = sr2appe.Text.Trim();
                srm.Name = sr2name.Text.Trim();
                srm.Company_And_Phone = sr2cap.Text.Trim();
                srml.Add(srm);
            }
            if (sr3appe.Text.Trim() != "" && sr3age.Text.Trim() != "" && sr3name.Text.Trim() != "" && sr3cap.Text.Trim() != "")
            {
                try
                {
                    srm.Age = Convert.ToInt32(sr3age.Text.Trim());
                }
                catch
                {
                    flag = "请在年龄栏中填写数字";
                }
                srm.Appellation = sr3appe.Text.Trim();
                srm.Name = sr3name.Text.Trim();
                srm.Company_And_Phone = sr3cap.Text.Trim();
                srml.Add(srm);
            }
            if (sr4appe.Text.Trim() != "" && sr4age.Text.Trim() != "" && sr4name.Text.Trim() != "" && sr4cap.Text.Trim() != "")
            {
                try
                {
                    srm.Age = Convert.ToInt32(sr4age.Text.Trim());
                }
                catch 
                {
                    flag = "请在年龄栏中填写数字";
                }
                srm.Appellation = sr4appe.Text.Trim();
                srm.Name = sr4name.Text.Trim();
                srm.Company_And_Phone = sr4cap.Text.Trim();
                srml.Add(srm);
            }
            String srmlstr = srm.EntityToJson(srml);
            
            
            TakePhotoForm takephotoform = new TakePhotoForm(uimstr,srmlstr);
            this.Hide();
            takephotoform.Show();
        }



    }
}
